About the dataset:

Sunspots are temporary phenomena on the Sun’s photosphere that appear as spots darker than the surrounding areas. They are regions of reduced surface temperature caused by concentrations of magnetic field flux that inhibit convection. Sunspots usually appear in pairs of opposite magnetic polarity. Their number varies according to the approximately 11-year solar cycle.

source: https://www.kaggle.com/robervalt/sunspots

Importing data:

Sunspots <- read_csv("C:/Users/User/OneDrive/Documents/3-SEMESTER/ts/Sunspots.csv")
## Warning: Missing column names filled in: 'X1' [1]
## 
## -- Column specification ------------------------------------------------------------------------
## cols(
##   X1 = col_double(),
##   Date = col_date(format = ""),
##   `Monthly Mean Total Sunspot Number` = col_double()
## )
View(Sunspots)

Cleaning and formating to time series format:

sapply(Sunspots, typeof)
##                                X1                              Date 
##                          "double"                          "double" 
## Monthly Mean Total Sunspot Number 
##                          "double"
sun_ts <- xts(Sunspots$`Monthly Mean Total Sunspot Number`, Sunspots$Date)

View(sun_ts)

colnames(sun_ts)[1] <- 'Values'

fig <- plot_ly(x = ~Sunspots$Date, y = ~Sunspots$`Monthly Mean Total Sunspot Number`,  
               mode = 'lines')

fig
## No trace type specified:
##   Based on info supplied, a 'scatter' trace seems appropriate.
##   Read more about this trace type -> https://plot.ly/r/reference/#scatter
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.

Checking null values:

sum(is.na(Sunspots$`Monthly Mean Total Sunspot Number`))
## [1] 0

Some more inferences:

frequency(Sunspots)
## [1] 1
summary(sun_ts)
##      Index                Values      
##  Min.   :1749-01-31   Min.   :  0.00  
##  1st Qu.:1817-01-31   1st Qu.: 23.90  
##  Median :1885-01-31   Median : 67.20  
##  Mean   :1885-01-29   Mean   : 81.78  
##  3rd Qu.:1953-01-31   3rd Qu.:122.50  
##  Max.   :2021-01-31   Max.   :398.20
min(sun_ts$Values)
## [1] 0
max(sun_ts$Values)
## [1] 398.2

Check stationarity:

adf.test(sun_ts)
## Warning in adf.test(sun_ts): p-value smaller than printed p-value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  sun_ts
## Dickey-Fuller = -7.0257, Lag order = 14, p-value = 0.01
## alternative hypothesis: stationary
adf.test(na.remove(diff(sun_ts))) 
## Warning in adf.test(na.remove(diff(sun_ts))): p-value smaller than printed p-
## value
## 
##  Augmented Dickey-Fuller Test
## 
## data:  na.remove(diff(sun_ts))
## Dickey-Fuller = -12.176, Lag order = 14, p-value = 0.01
## alternative hypothesis: stationary

p-value < 0.05 indicates the TS is stationary
we reject the null in favour of the
alternative hypothesis that the time series is stationary

ACF and PACF plots:

autoplot(acf(sun_ts,plot=FALSE)) + 
  labs(title="Monthly Mean Total Sunspot Number") + 
  theme_classic()

pacf(sun_ts)